Skip to content

gh-151126: Fix a possible crash during the startup with no memory under Py_STACKREF_DEBUG#152478

Merged
sobolevn merged 2 commits into
python:mainfrom
sobolevn:issue-151126-Py_STACKREF_DEBUG
Jun 30, 2026
Merged

gh-151126: Fix a possible crash during the startup with no memory under Py_STACKREF_DEBUG#152478
sobolevn merged 2 commits into
python:mainfrom
sobolevn:issue-151126-Py_STACKREF_DEBUG

Conversation

@sobolevn

@sobolevn sobolevn commented Jun 28, 2026

Copy link
Copy Markdown
Member
  • _Py_hashtable_new_full can return NULL (when no memory is left) and does not set an exception
  • interp->open_stackrefs_table and interp->closed_stackrefs_table are required to be non-NULL
  • If they are, we can possibly get a NULL deref from using them

Comment on lines +1 to +2
Fix a possible crash during the interpreter startup under a memory pressure
with ``Py_STACKREF_DEBUG`` enabled.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really need a news entry? I can't imagine why downstream users would want this build.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, removed :)

@sobolevn sobolevn added skip news needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jun 28, 2026
@sobolevn sobolevn requested a review from ZeroIntensity June 29, 2026 21:29
@sobolevn sobolevn merged commit ecdef17 into python:main Jun 30, 2026
63 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @sobolevn for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jun 30, 2026

Copy link
Copy Markdown

GH-152677 is a backport of this pull request to the 3.15 branch.

@miss-islington-app

Copy link
Copy Markdown

Sorry, @sobolevn, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker ecdef1773006529b0fea6639d0effeecbb41679c 3.13

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jun 30, 2026
@bedevere-app

bedevere-app Bot commented Jun 30, 2026

Copy link
Copy Markdown

GH-152678 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jun 30, 2026
@sobolevn

Copy link
Copy Markdown
Member Author

3.13 does not have this code, removed the backport label.

@sobolevn sobolevn removed the needs backport to 3.13 bugs and security fixes label Jun 30, 2026
sobolevn added a commit that referenced this pull request Jun 30, 2026
…ory under `Py_STACKREF_DEBUG` (GH-152478) (#152678)

gh-151126: Fix a possible crash during the startup with no memory under `Py_STACKREF_DEBUG` (GH-152478)
(cherry picked from commit ecdef17)

Co-authored-by: sobolevn <mail@sobolevn.me>
sobolevn added a commit that referenced this pull request Jun 30, 2026
…ory under `Py_STACKREF_DEBUG` (GH-152478) (#152677)

gh-151126: Fix a possible crash during the startup with no memory under `Py_STACKREF_DEBUG` (GH-152478)
(cherry picked from commit ecdef17)

Co-authored-by: sobolevn <mail@sobolevn.me>
maurycy added a commit to maurycy/cpython that referenced this pull request Jul 1, 2026
* main: (266 commits)
  pythongh-151626: Fix tests that fail when PYTHONPYCACHEPREFIX is set (pythonGH-151952)
  pythongh-152728: IDLE - move 3 toplevel fix_xyz functions to idlelb.util (python#152729)
  pythongh-152711: Add pythoninfo-build command to Platforms/Android (python#152713)
  pythongh-152715: Add pythoninfo-build command to Platforms/Apple (python#152716)
  pythongh-152433: Windows: enable mmapmodule for UWP (python#152473)
  pythongh-152433: Windows: use GetFileSizeEx instead of GetFileSize for memory mapped files (python#152383)
  pythonGH-81881: Raise `SpecialFileError` for sockets and devices in `shutil.copyfile` (python#142693)
  pythongh-152502: Detect the curses mouse interface and is_* methods portably (pythonGH-152705)
  pythongh-145857: Replace `DELETE_GLOBAL` with `PUSH_NULL; STORE_GLOBAL` (pythonGH-146314)
  pythongh-145854: Replace `DELETE_NAME` with `PUSH_NULL; STORE_NAME` (pythonGH-146006)
  pythongh-152680: Detect container/VM in test.pythoninfo (python#152668)
  pythongh-152682: Fix NULL dereference on OOM in `symtable_visit_type_param_bound_or_default` (python#152684)
  pythongh-151881: Skip tk_inactive negativity check on Windows (pythonGH-152683)
  pythongh-152546: Refactor `mappingproxy.__new__` to use `PyDictProxy_New` (python#152547)
  pythongh-151126: Fix a possible crash during the startup with no memory under `Py_STACKREF_DEBUG` (python#152478)
  pythongh-152635: Raise MemoryError when the lock allocation fails in `_interpchannels.create()` (python#152642)
  pythongh-151029: Fix `test_remote_exec_deleted_static_executable` on static installed builds (pythonGH-152653)
  pythongh-121249: Deprecate using F/D type codes in the struct module (python#152309)
  pythongh-152192: Fix JUMP_BACKWARD passing a truncated oparg to the jit tracer (pythonGH-152382)
  Don't require the `_test{internal}capi` modules in `test_monitoring.py` (python#152311)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants